package cn.uikit.demo.media

import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.os.Message
import cn.uikit.demo.databinding.ActivityVideoBinding
import sivin.uikit.framework.BindingActivity

class VideoActivity : BindingActivity<ActivityVideoBinding>(
    ActivityVideoBinding::inflate
) {
    companion object {
        private const val KEY_URI = "key_uri"
        private const val KEY_IS_VOD = "key_is_vod"
        fun launch(context: Context, uri: String, isVod: Boolean = true) {
            val startIntent = Intent(context, VideoActivity::class.java)
            startIntent.putExtra(KEY_URI, uri)
            startIntent.putExtra(KEY_IS_VOD, isVod)
            context.startActivity(startIntent)
        }
    }

    private val mUri: String by lazy {
        intent?.getStringExtra(KEY_URI) ?: ""
    }

    private val mIsVod by lazy {
        intent?.getBooleanExtra(KEY_IS_VOD, true)
    }

    private class PlaybackHandler(looper: Looper) : Handler(looper) {
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
        }
    }

    private lateinit var mPlaybackThread: HandlerThread
    private lateinit var mPlayHandler: PlaybackHandler
    private val mUiHandler by lazy {
        Handler(mainLooper)
    }

    private val mMediaPlayer by lazy {
        MediaPlayer().apply {

        }
    }

    override fun onViewCreate(savedInstanceState: Bundle?) {
        super.onViewCreate(savedInstanceState)
        initData()
    }

    private fun initData() {
        mPlaybackThread = HandlerThread("playback thread")
        mPlaybackThread.start()
        mPlayHandler = PlaybackHandler(mPlaybackThread.looper)

    }


}